
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 02/08/2012 12:40:12
-- Generated from EDMX file: C:\Users\-aaronljx-\Documents\Visual Studio 2010\Projects\ThisIsELearning\ThisIsELearning\Model\DataModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [ThisIsELearning];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_LearningProfileLearningProfileItem]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[LearningProfileItems] DROP CONSTRAINT [FK_LearningProfileLearningProfileItem];
GO
IF OBJECT_ID(N'[dbo].[FK_LearningProfileStudent]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[LearningProfiles] DROP CONSTRAINT [FK_LearningProfileStudent];
GO
IF OBJECT_ID(N'[dbo].[FK_LearningStyleLearningProfileItem]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[LearningProfileItems] DROP CONSTRAINT [FK_LearningStyleLearningProfileItem];
GO
IF OBJECT_ID(N'[dbo].[FK_CourseCourseTopic]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CourseTopics] DROP CONSTRAINT [FK_CourseCourseTopic];
GO
IF OBJECT_ID(N'[dbo].[FK_CourseTopicTopicContent]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TopicContents] DROP CONSTRAINT [FK_CourseTopicTopicContent];
GO
IF OBJECT_ID(N'[dbo].[FK_LearningStyleTopicContent]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TopicContents] DROP CONSTRAINT [FK_LearningStyleTopicContent];
GO
IF OBJECT_ID(N'[dbo].[FK_CourseTopicTopicQuestion]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TopicQuestions] DROP CONSTRAINT [FK_CourseTopicTopicQuestion];
GO
IF OBJECT_ID(N'[dbo].[FK_LearningStyleTopicQuestion]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TopicQuestions] DROP CONSTRAINT [FK_LearningStyleTopicQuestion];
GO
IF OBJECT_ID(N'[dbo].[FK_ItemObjectTypeCanvasItem]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CanvasItems] DROP CONSTRAINT [FK_ItemObjectTypeCanvasItem];
GO
IF OBJECT_ID(N'[dbo].[FK_ContentCanvasCanvasItem]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CanvasItems] DROP CONSTRAINT [FK_ContentCanvasCanvasItem];
GO
IF OBJECT_ID(N'[dbo].[FK_TopicContentContentCanvas]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ContentCanvas] DROP CONSTRAINT [FK_TopicContentContentCanvas];
GO
IF OBJECT_ID(N'[dbo].[FK_LearningTrailTrailItem]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TrailItems] DROP CONSTRAINT [FK_LearningTrailTrailItem];
GO
IF OBJECT_ID(N'[dbo].[FK_CourseTopicTrailItem]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TrailItems] DROP CONSTRAINT [FK_CourseTopicTrailItem];
GO
IF OBJECT_ID(N'[dbo].[FK_CourseLearningTrail]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[LearningTrails] DROP CONSTRAINT [FK_CourseLearningTrail];
GO
IF OBJECT_ID(N'[dbo].[FK_TopicContentLearningSession]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[LearningSessions] DROP CONSTRAINT [FK_TopicContentLearningSession];
GO
IF OBJECT_ID(N'[dbo].[FK_ContentCanvasLearningSession]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[LearningSessions] DROP CONSTRAINT [FK_ContentCanvasLearningSession];
GO
IF OBJECT_ID(N'[dbo].[FK_LearningTrailLearningSession]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[LearningSessions] DROP CONSTRAINT [FK_LearningTrailLearningSession];
GO
IF OBJECT_ID(N'[dbo].[FK_LearningSessionStudent]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[LearningSessions] DROP CONSTRAINT [FK_LearningSessionStudent];
GO
IF OBJECT_ID(N'[dbo].[FK_StudentAssesmentLearningSession]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[StudentAssesments] DROP CONSTRAINT [FK_StudentAssesmentLearningSession];
GO
IF OBJECT_ID(N'[dbo].[FK_StudentAssesmentAssesmentItem]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AssesmentItems] DROP CONSTRAINT [FK_StudentAssesmentAssesmentItem];
GO
IF OBJECT_ID(N'[dbo].[FK_TopicQuestionAssesmentItem]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AssesmentItems] DROP CONSTRAINT [FK_TopicQuestionAssesmentItem];
GO
IF OBJECT_ID(N'[dbo].[FK_StudentAssesmentStudent]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[StudentAssesments] DROP CONSTRAINT [FK_StudentAssesmentStudent];
GO
IF OBJECT_ID(N'[dbo].[FK_SubscriptionStudent]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Subscriptions] DROP CONSTRAINT [FK_SubscriptionStudent];
GO
IF OBJECT_ID(N'[dbo].[FK_PublishingCompanyPublisher]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Users_Publisher] DROP CONSTRAINT [FK_PublishingCompanyPublisher];
GO
IF OBJECT_ID(N'[dbo].[FK_PublisherCourse]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Courses] DROP CONSTRAINT [FK_PublisherCourse];
GO
IF OBJECT_ID(N'[dbo].[FK_ContentCanvasNotificationMessage]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EncouragementMessages] DROP CONSTRAINT [FK_ContentCanvasNotificationMessage];
GO
IF OBJECT_ID(N'[dbo].[FK_NotificationMessageStudentAssesment]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[StudentAssesments] DROP CONSTRAINT [FK_NotificationMessageStudentAssesment];
GO
IF OBJECT_ID(N'[dbo].[FK_TopicQuestionContentCanvas]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ContentCanvas] DROP CONSTRAINT [FK_TopicQuestionContentCanvas];
GO
IF OBJECT_ID(N'[dbo].[FK_ParentStudent]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Users_Student] DROP CONSTRAINT [FK_ParentStudent];
GO
IF OBJECT_ID(N'[dbo].[FK_TopicQuestionAnswer]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AnswerChoices] DROP CONSTRAINT [FK_TopicQuestionAnswer];
GO
IF OBJECT_ID(N'[dbo].[FK_CourseTag]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Tags] DROP CONSTRAINT [FK_CourseTag];
GO
IF OBJECT_ID(N'[dbo].[FK_CourseTopicTag]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Tags] DROP CONSTRAINT [FK_CourseTopicTag];
GO
IF OBJECT_ID(N'[dbo].[FK_Student_inherits_User]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Users_Student] DROP CONSTRAINT [FK_Student_inherits_User];
GO
IF OBJECT_ID(N'[dbo].[FK_Publisher_inherits_User]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Users_Publisher] DROP CONSTRAINT [FK_Publisher_inherits_User];
GO
IF OBJECT_ID(N'[dbo].[FK_Parent_inherits_User]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Users_Parent] DROP CONSTRAINT [FK_Parent_inherits_User];
GO
IF OBJECT_ID(N'[dbo].[FK_SingleChoiceAnswer_inherits_AnswerChoice]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AnswerChoices_SingleChoiceAnswer] DROP CONSTRAINT [FK_SingleChoiceAnswer_inherits_AnswerChoice];
GO
IF OBJECT_ID(N'[dbo].[FK_Admin_inherits_User]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Users_Admin] DROP CONSTRAINT [FK_Admin_inherits_User];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Users]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Users];
GO
IF OBJECT_ID(N'[dbo].[LearningProfileItems]', 'U') IS NOT NULL
    DROP TABLE [dbo].[LearningProfileItems];
GO
IF OBJECT_ID(N'[dbo].[LearningProfiles]', 'U') IS NOT NULL
    DROP TABLE [dbo].[LearningProfiles];
GO
IF OBJECT_ID(N'[dbo].[LearningStyles]', 'U') IS NOT NULL
    DROP TABLE [dbo].[LearningStyles];
GO
IF OBJECT_ID(N'[dbo].[TopicContents]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TopicContents];
GO
IF OBJECT_ID(N'[dbo].[CourseTopics]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CourseTopics];
GO
IF OBJECT_ID(N'[dbo].[Courses]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Courses];
GO
IF OBJECT_ID(N'[dbo].[TopicQuestions]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TopicQuestions];
GO
IF OBJECT_ID(N'[dbo].[ContentCanvas]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ContentCanvas];
GO
IF OBJECT_ID(N'[dbo].[CanvasItems]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CanvasItems];
GO
IF OBJECT_ID(N'[dbo].[ItemObjectTypes]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ItemObjectTypes];
GO
IF OBJECT_ID(N'[dbo].[TrailItems]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TrailItems];
GO
IF OBJECT_ID(N'[dbo].[LearningTrails]', 'U') IS NOT NULL
    DROP TABLE [dbo].[LearningTrails];
GO
IF OBJECT_ID(N'[dbo].[LearningSessions]', 'U') IS NOT NULL
    DROP TABLE [dbo].[LearningSessions];
GO
IF OBJECT_ID(N'[dbo].[StudentAssesments]', 'U') IS NOT NULL
    DROP TABLE [dbo].[StudentAssesments];
GO
IF OBJECT_ID(N'[dbo].[AssesmentItems]', 'U') IS NOT NULL
    DROP TABLE [dbo].[AssesmentItems];
GO
IF OBJECT_ID(N'[dbo].[Subscriptions]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Subscriptions];
GO
IF OBJECT_ID(N'[dbo].[EncouragementMessages]', 'U') IS NOT NULL
    DROP TABLE [dbo].[EncouragementMessages];
GO
IF OBJECT_ID(N'[dbo].[PublishingCompanies]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PublishingCompanies];
GO
IF OBJECT_ID(N'[dbo].[AnswerChoices]', 'U') IS NOT NULL
    DROP TABLE [dbo].[AnswerChoices];
GO
IF OBJECT_ID(N'[dbo].[Tags]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Tags];
GO
IF OBJECT_ID(N'[dbo].[SystemConfigs]', 'U') IS NOT NULL
    DROP TABLE [dbo].[SystemConfigs];
GO
IF OBJECT_ID(N'[dbo].[Users_Student]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Users_Student];
GO
IF OBJECT_ID(N'[dbo].[Users_Publisher]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Users_Publisher];
GO
IF OBJECT_ID(N'[dbo].[Users_Parent]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Users_Parent];
GO
IF OBJECT_ID(N'[dbo].[AnswerChoices_SingleChoiceAnswer]', 'U') IS NOT NULL
    DROP TABLE [dbo].[AnswerChoices_SingleChoiceAnswer];
GO
IF OBJECT_ID(N'[dbo].[Users_Admin]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Users_Admin];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Users'
CREATE TABLE [dbo].[Users] (
    [userId] int IDENTITY(1,1) NOT NULL,
    [loginId] nvarchar(25)  NOT NULL,
    [password] nvarchar(max)  NOT NULL,
    [firstName] nvarchar(25)  NOT NULL,
    [lastName] nvarchar(25)  NOT NULL,
    [contactNumber] nchar(10)  NOT NULL,
    [email] nvarchar(30)  NOT NULL,
    [address] nvarchar(max)  NOT NULL,
    [dateRegistered] datetime  NOT NULL,
    [gender] nvarchar(1)  NOT NULL,
    [dateOfBirth] datetime  NOT NULL
);
GO

-- Creating table 'LearningProfileItems'
CREATE TABLE [dbo].[LearningProfileItems] (
    [learningProfileItemId] int IDENTITY(1,1) NOT NULL,
    [ratio] float  NOT NULL,
    [learningProfile_learningProfileId] int  NOT NULL,
    [learningStyle_learningStyleId] int  NOT NULL
);
GO

-- Creating table 'LearningProfiles'
CREATE TABLE [dbo].[LearningProfiles] (
    [learningProfileId] int IDENTITY(1,1) NOT NULL,
    [creationDate] datetime  NOT NULL,
    [student_userId] int  NOT NULL
);
GO

-- Creating table 'LearningStyles'
CREATE TABLE [dbo].[LearningStyles] (
    [learningStyleId] int IDENTITY(1,1) NOT NULL,
    [learningStyleName] nvarchar(25)  NOT NULL,
    [learningStyleDescription] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'TopicContents'
CREATE TABLE [dbo].[TopicContents] (
    [topicContentId] int IDENTITY(1,1) NOT NULL,
    [totalCanvases] int  NULL,
    [importance] nvarchar(2)  NOT NULL,
    [isPublished] bit  NOT NULL,
    [courseTopic_courseTopicId] int  NOT NULL,
    [learningStyle_learningStyleId] int  NOT NULL
);
GO

-- Creating table 'CourseTopics'
CREATE TABLE [dbo].[CourseTopics] (
    [courseTopicId] int IDENTITY(1,1) NOT NULL,
    [courseTopicName] nvarchar(max)  NOT NULL,
    [courseTopicDescription] nvarchar(max)  NOT NULL,
    [courseTopicNumber] int  NOT NULL,
    [course_courseId] int  NOT NULL
);
GO

-- Creating table 'Courses'
CREATE TABLE [dbo].[Courses] (
    [courseId] int IDENTITY(1,1) NOT NULL,
    [courseName] nvarchar(max)  NOT NULL,
    [courseDescription] nvarchar(max)  NOT NULL,
    [grade] int  NOT NULL,
    [isPublished] bit  NOT NULL,
    [publisher_userId] int  NOT NULL
);
GO

-- Creating table 'TopicQuestions'
CREATE TABLE [dbo].[TopicQuestions] (
    [topicQuestionId] int IDENTITY(1,1) NOT NULL,
    [difficultyLevel] int  NOT NULL,
    [courseTopic_courseTopicId] int  NOT NULL,
    [learningStyle_learningStyleId] int  NOT NULL
);
GO

-- Creating table 'ContentCanvas'
CREATE TABLE [dbo].[ContentCanvas] (
    [contentCanvasId] int IDENTITY(1,1) NOT NULL,
    [contentType] nvarchar(2)  NOT NULL,
    [canvasNumber] int  NOT NULL,
    [TopicContentContentCanvas_ContentCanvas_topicContentId] int  NULL,
    [TopicQuestionContentCanvas_ContentCanvas_topicQuestionId] int  NULL
);
GO

-- Creating table 'CanvasItems'
CREATE TABLE [dbo].[CanvasItems] (
    [canvasItemId] int IDENTITY(1,1) NOT NULL,
    [itemObjectData] varbinary(max)  NOT NULL,
    [itemObjectType_itemObjectTypeId] int  NOT NULL,
    [contentCanvas_contentCanvasId] int  NOT NULL
);
GO

-- Creating table 'ItemObjectTypes'
CREATE TABLE [dbo].[ItemObjectTypes] (
    [itemObjectTypeId] int IDENTITY(1,1) NOT NULL,
    [itemObjectTypeName] nvarchar(max)  NOT NULL,
    [itemObjectTypeDescription] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'TrailItems'
CREATE TABLE [dbo].[TrailItems] (
    [trailItemId] int IDENTITY(1,1) NOT NULL,
    [trailItemNumber] int  NOT NULL,
    [learningTrail_learningTrailId] int  NOT NULL,
    [courseTopic_courseTopicId] int  NOT NULL
);
GO

-- Creating table 'LearningTrails'
CREATE TABLE [dbo].[LearningTrails] (
    [learningTrailId] int IDENTITY(1,1) NOT NULL,
    [dateCreated] datetime  NOT NULL,
    [learningTrailName] nvarchar(max)  NOT NULL,
    [isSessionCustomized] bit  NOT NULL,
    [course_courseId] int  NOT NULL
);
GO

-- Creating table 'LearningSessions'
CREATE TABLE [dbo].[LearningSessions] (
    [learningSessionId] int IDENTITY(1,1) NOT NULL,
    [isCompleted] bit  NOT NULL,
    [dateCreated] datetime  NOT NULL,
    [dateEnded] datetime  NULL,
    [topicContent_topicContentId] int  NOT NULL,
    [contentCanvas_contentCanvasId] int  NOT NULL,
    [learningTrail_learningTrailId] int  NOT NULL,
    [student_userId] int  NOT NULL
);
GO

-- Creating table 'StudentAssesments'
CREATE TABLE [dbo].[StudentAssesments] (
    [studentAssesmentId] int IDENTITY(1,1) NOT NULL,
    [assesmentDate] datetime  NOT NULL,
    [assesmentMark] decimal(3,3)  NULL,
    [learningSession_learningSessionId] int  NOT NULL,
    [student_userId] int  NOT NULL,
    [notificationMessage_encouragementMessageId] int  NOT NULL
);
GO

-- Creating table 'AssesmentItems'
CREATE TABLE [dbo].[AssesmentItems] (
    [assesmentItemId] int IDENTITY(1,1) NOT NULL,
    [isCorrect] bit  NOT NULL,
    [studentAssesment_studentAssesmentId] int  NOT NULL,
    [topicQuestion_topicQuestionId] int  NOT NULL
);
GO

-- Creating table 'Subscriptions'
CREATE TABLE [dbo].[Subscriptions] (
    [subscriptionId] int IDENTITY(1,1) NOT NULL,
    [subscriptionDate] datetime  NOT NULL,
    [subscriptionExpiryDate] datetime  NOT NULL,
    [isActivated] bit  NOT NULL,
    [student_userId] int  NOT NULL
);
GO

-- Creating table 'EncouragementMessages'
CREATE TABLE [dbo].[EncouragementMessages] (
    [encouragementMessageId] int IDENTITY(1,1) NOT NULL,
    [contentCanvas_contentCanvasId] int  NOT NULL
);
GO

-- Creating table 'PublishingCompanies'
CREATE TABLE [dbo].[PublishingCompanies] (
    [publishingCompanyId] int IDENTITY(1,1) NOT NULL,
    [companyName] nvarchar(max)  NOT NULL,
    [companyAddress] nvarchar(max)  NOT NULL,
    [companyContactNumber] nvarchar(10)  NOT NULL,
    [staffAuthorizationCode] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'AnswerChoices'
CREATE TABLE [dbo].[AnswerChoices] (
    [answerId] int IDENTITY(1,1) NOT NULL,
    [answerType] int  NOT NULL,
    [TopicQuestionAnswer_Answer_topicQuestionId] int  NOT NULL
);
GO

-- Creating table 'Tags'
CREATE TABLE [dbo].[Tags] (
    [tagId] int IDENTITY(1,1) NOT NULL,
    [keyword] nvarchar(max)  NOT NULL,
    [taggedEntity] int  NOT NULL,
    [course_courseId] int  NULL,
    [courseTopic_courseTopicId] int  NULL
);
GO

-- Creating table 'SystemConfigs'
CREATE TABLE [dbo].[SystemConfigs] (
    [configId] int IDENTITY(1,1) NOT NULL,
    [key] nvarchar(max)  NOT NULL,
    [data] nvarchar(max)  NOT NULL,
    [lastModified] datetime  NOT NULL
);
GO

-- Creating table 'Users_Student'
CREATE TABLE [dbo].[Users_Student] (
    [school] nvarchar(max)  NOT NULL,
    [grade] int  NOT NULL,
    [userId] int  NOT NULL,
    [parent_userId] int  NOT NULL
);
GO

-- Creating table 'Users_Publisher'
CREATE TABLE [dbo].[Users_Publisher] (
    [isActivated] bit  NULL,
    [userId] int  NOT NULL,
    [publishingCompany_publishingCompanyId] int  NOT NULL
);
GO

-- Creating table 'Users_Parent'
CREATE TABLE [dbo].[Users_Parent] (
    [relationship] nchar(2)  NOT NULL,
    [userId] int  NOT NULL
);
GO

-- Creating table 'AnswerChoices_SingleChoiceAnswer'
CREATE TABLE [dbo].[AnswerChoices_SingleChoiceAnswer] (
    [answerChoice] nvarchar(max)  NOT NULL,
    [isAnswer] bit  NOT NULL,
    [answerId] int  NOT NULL
);
GO

-- Creating table 'Users_Admin'
CREATE TABLE [dbo].[Users_Admin] (
    [userId] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [userId] in table 'Users'
ALTER TABLE [dbo].[Users]
ADD CONSTRAINT [PK_Users]
    PRIMARY KEY CLUSTERED ([userId] ASC);
GO

-- Creating primary key on [learningProfileItemId] in table 'LearningProfileItems'
ALTER TABLE [dbo].[LearningProfileItems]
ADD CONSTRAINT [PK_LearningProfileItems]
    PRIMARY KEY CLUSTERED ([learningProfileItemId] ASC);
GO

-- Creating primary key on [learningProfileId] in table 'LearningProfiles'
ALTER TABLE [dbo].[LearningProfiles]
ADD CONSTRAINT [PK_LearningProfiles]
    PRIMARY KEY CLUSTERED ([learningProfileId] ASC);
GO

-- Creating primary key on [learningStyleId] in table 'LearningStyles'
ALTER TABLE [dbo].[LearningStyles]
ADD CONSTRAINT [PK_LearningStyles]
    PRIMARY KEY CLUSTERED ([learningStyleId] ASC);
GO

-- Creating primary key on [topicContentId] in table 'TopicContents'
ALTER TABLE [dbo].[TopicContents]
ADD CONSTRAINT [PK_TopicContents]
    PRIMARY KEY CLUSTERED ([topicContentId] ASC);
GO

-- Creating primary key on [courseTopicId] in table 'CourseTopics'
ALTER TABLE [dbo].[CourseTopics]
ADD CONSTRAINT [PK_CourseTopics]
    PRIMARY KEY CLUSTERED ([courseTopicId] ASC);
GO

-- Creating primary key on [courseId] in table 'Courses'
ALTER TABLE [dbo].[Courses]
ADD CONSTRAINT [PK_Courses]
    PRIMARY KEY CLUSTERED ([courseId] ASC);
GO

-- Creating primary key on [topicQuestionId] in table 'TopicQuestions'
ALTER TABLE [dbo].[TopicQuestions]
ADD CONSTRAINT [PK_TopicQuestions]
    PRIMARY KEY CLUSTERED ([topicQuestionId] ASC);
GO

-- Creating primary key on [contentCanvasId] in table 'ContentCanvas'
ALTER TABLE [dbo].[ContentCanvas]
ADD CONSTRAINT [PK_ContentCanvas]
    PRIMARY KEY CLUSTERED ([contentCanvasId] ASC);
GO

-- Creating primary key on [canvasItemId] in table 'CanvasItems'
ALTER TABLE [dbo].[CanvasItems]
ADD CONSTRAINT [PK_CanvasItems]
    PRIMARY KEY CLUSTERED ([canvasItemId] ASC);
GO

-- Creating primary key on [itemObjectTypeId] in table 'ItemObjectTypes'
ALTER TABLE [dbo].[ItemObjectTypes]
ADD CONSTRAINT [PK_ItemObjectTypes]
    PRIMARY KEY CLUSTERED ([itemObjectTypeId] ASC);
GO

-- Creating primary key on [trailItemId] in table 'TrailItems'
ALTER TABLE [dbo].[TrailItems]
ADD CONSTRAINT [PK_TrailItems]
    PRIMARY KEY CLUSTERED ([trailItemId] ASC);
GO

-- Creating primary key on [learningTrailId] in table 'LearningTrails'
ALTER TABLE [dbo].[LearningTrails]
ADD CONSTRAINT [PK_LearningTrails]
    PRIMARY KEY CLUSTERED ([learningTrailId] ASC);
GO

-- Creating primary key on [learningSessionId] in table 'LearningSessions'
ALTER TABLE [dbo].[LearningSessions]
ADD CONSTRAINT [PK_LearningSessions]
    PRIMARY KEY CLUSTERED ([learningSessionId] ASC);
GO

-- Creating primary key on [studentAssesmentId] in table 'StudentAssesments'
ALTER TABLE [dbo].[StudentAssesments]
ADD CONSTRAINT [PK_StudentAssesments]
    PRIMARY KEY CLUSTERED ([studentAssesmentId] ASC);
GO

-- Creating primary key on [assesmentItemId] in table 'AssesmentItems'
ALTER TABLE [dbo].[AssesmentItems]
ADD CONSTRAINT [PK_AssesmentItems]
    PRIMARY KEY CLUSTERED ([assesmentItemId] ASC);
GO

-- Creating primary key on [subscriptionId] in table 'Subscriptions'
ALTER TABLE [dbo].[Subscriptions]
ADD CONSTRAINT [PK_Subscriptions]
    PRIMARY KEY CLUSTERED ([subscriptionId] ASC);
GO

-- Creating primary key on [encouragementMessageId] in table 'EncouragementMessages'
ALTER TABLE [dbo].[EncouragementMessages]
ADD CONSTRAINT [PK_EncouragementMessages]
    PRIMARY KEY CLUSTERED ([encouragementMessageId] ASC);
GO

-- Creating primary key on [publishingCompanyId] in table 'PublishingCompanies'
ALTER TABLE [dbo].[PublishingCompanies]
ADD CONSTRAINT [PK_PublishingCompanies]
    PRIMARY KEY CLUSTERED ([publishingCompanyId] ASC);
GO

-- Creating primary key on [answerId] in table 'AnswerChoices'
ALTER TABLE [dbo].[AnswerChoices]
ADD CONSTRAINT [PK_AnswerChoices]
    PRIMARY KEY CLUSTERED ([answerId] ASC);
GO

-- Creating primary key on [tagId] in table 'Tags'
ALTER TABLE [dbo].[Tags]
ADD CONSTRAINT [PK_Tags]
    PRIMARY KEY CLUSTERED ([tagId] ASC);
GO

-- Creating primary key on [configId] in table 'SystemConfigs'
ALTER TABLE [dbo].[SystemConfigs]
ADD CONSTRAINT [PK_SystemConfigs]
    PRIMARY KEY CLUSTERED ([configId] ASC);
GO

-- Creating primary key on [userId] in table 'Users_Student'
ALTER TABLE [dbo].[Users_Student]
ADD CONSTRAINT [PK_Users_Student]
    PRIMARY KEY CLUSTERED ([userId] ASC);
GO

-- Creating primary key on [userId] in table 'Users_Publisher'
ALTER TABLE [dbo].[Users_Publisher]
ADD CONSTRAINT [PK_Users_Publisher]
    PRIMARY KEY CLUSTERED ([userId] ASC);
GO

-- Creating primary key on [userId] in table 'Users_Parent'
ALTER TABLE [dbo].[Users_Parent]
ADD CONSTRAINT [PK_Users_Parent]
    PRIMARY KEY CLUSTERED ([userId] ASC);
GO

-- Creating primary key on [answerId] in table 'AnswerChoices_SingleChoiceAnswer'
ALTER TABLE [dbo].[AnswerChoices_SingleChoiceAnswer]
ADD CONSTRAINT [PK_AnswerChoices_SingleChoiceAnswer]
    PRIMARY KEY CLUSTERED ([answerId] ASC);
GO

-- Creating primary key on [userId] in table 'Users_Admin'
ALTER TABLE [dbo].[Users_Admin]
ADD CONSTRAINT [PK_Users_Admin]
    PRIMARY KEY CLUSTERED ([userId] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [learningProfile_learningProfileId] in table 'LearningProfileItems'
ALTER TABLE [dbo].[LearningProfileItems]
ADD CONSTRAINT [FK_LearningProfileLearningProfileItem]
    FOREIGN KEY ([learningProfile_learningProfileId])
    REFERENCES [dbo].[LearningProfiles]
        ([learningProfileId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_LearningProfileLearningProfileItem'
CREATE INDEX [IX_FK_LearningProfileLearningProfileItem]
ON [dbo].[LearningProfileItems]
    ([learningProfile_learningProfileId]);
GO

-- Creating foreign key on [student_userId] in table 'LearningProfiles'
ALTER TABLE [dbo].[LearningProfiles]
ADD CONSTRAINT [FK_LearningProfileStudent]
    FOREIGN KEY ([student_userId])
    REFERENCES [dbo].[Users_Student]
        ([userId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_LearningProfileStudent'
CREATE INDEX [IX_FK_LearningProfileStudent]
ON [dbo].[LearningProfiles]
    ([student_userId]);
GO

-- Creating foreign key on [learningStyle_learningStyleId] in table 'LearningProfileItems'
ALTER TABLE [dbo].[LearningProfileItems]
ADD CONSTRAINT [FK_LearningStyleLearningProfileItem]
    FOREIGN KEY ([learningStyle_learningStyleId])
    REFERENCES [dbo].[LearningStyles]
        ([learningStyleId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_LearningStyleLearningProfileItem'
CREATE INDEX [IX_FK_LearningStyleLearningProfileItem]
ON [dbo].[LearningProfileItems]
    ([learningStyle_learningStyleId]);
GO

-- Creating foreign key on [course_courseId] in table 'CourseTopics'
ALTER TABLE [dbo].[CourseTopics]
ADD CONSTRAINT [FK_CourseCourseTopic]
    FOREIGN KEY ([course_courseId])
    REFERENCES [dbo].[Courses]
        ([courseId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CourseCourseTopic'
CREATE INDEX [IX_FK_CourseCourseTopic]
ON [dbo].[CourseTopics]
    ([course_courseId]);
GO

-- Creating foreign key on [courseTopic_courseTopicId] in table 'TopicContents'
ALTER TABLE [dbo].[TopicContents]
ADD CONSTRAINT [FK_CourseTopicTopicContent]
    FOREIGN KEY ([courseTopic_courseTopicId])
    REFERENCES [dbo].[CourseTopics]
        ([courseTopicId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CourseTopicTopicContent'
CREATE INDEX [IX_FK_CourseTopicTopicContent]
ON [dbo].[TopicContents]
    ([courseTopic_courseTopicId]);
GO

-- Creating foreign key on [learningStyle_learningStyleId] in table 'TopicContents'
ALTER TABLE [dbo].[TopicContents]
ADD CONSTRAINT [FK_LearningStyleTopicContent]
    FOREIGN KEY ([learningStyle_learningStyleId])
    REFERENCES [dbo].[LearningStyles]
        ([learningStyleId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_LearningStyleTopicContent'
CREATE INDEX [IX_FK_LearningStyleTopicContent]
ON [dbo].[TopicContents]
    ([learningStyle_learningStyleId]);
GO

-- Creating foreign key on [courseTopic_courseTopicId] in table 'TopicQuestions'
ALTER TABLE [dbo].[TopicQuestions]
ADD CONSTRAINT [FK_CourseTopicTopicQuestion]
    FOREIGN KEY ([courseTopic_courseTopicId])
    REFERENCES [dbo].[CourseTopics]
        ([courseTopicId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CourseTopicTopicQuestion'
CREATE INDEX [IX_FK_CourseTopicTopicQuestion]
ON [dbo].[TopicQuestions]
    ([courseTopic_courseTopicId]);
GO

-- Creating foreign key on [learningStyle_learningStyleId] in table 'TopicQuestions'
ALTER TABLE [dbo].[TopicQuestions]
ADD CONSTRAINT [FK_LearningStyleTopicQuestion]
    FOREIGN KEY ([learningStyle_learningStyleId])
    REFERENCES [dbo].[LearningStyles]
        ([learningStyleId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_LearningStyleTopicQuestion'
CREATE INDEX [IX_FK_LearningStyleTopicQuestion]
ON [dbo].[TopicQuestions]
    ([learningStyle_learningStyleId]);
GO

-- Creating foreign key on [itemObjectType_itemObjectTypeId] in table 'CanvasItems'
ALTER TABLE [dbo].[CanvasItems]
ADD CONSTRAINT [FK_ItemObjectTypeCanvasItem]
    FOREIGN KEY ([itemObjectType_itemObjectTypeId])
    REFERENCES [dbo].[ItemObjectTypes]
        ([itemObjectTypeId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ItemObjectTypeCanvasItem'
CREATE INDEX [IX_FK_ItemObjectTypeCanvasItem]
ON [dbo].[CanvasItems]
    ([itemObjectType_itemObjectTypeId]);
GO

-- Creating foreign key on [contentCanvas_contentCanvasId] in table 'CanvasItems'
ALTER TABLE [dbo].[CanvasItems]
ADD CONSTRAINT [FK_ContentCanvasCanvasItem]
    FOREIGN KEY ([contentCanvas_contentCanvasId])
    REFERENCES [dbo].[ContentCanvas]
        ([contentCanvasId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ContentCanvasCanvasItem'
CREATE INDEX [IX_FK_ContentCanvasCanvasItem]
ON [dbo].[CanvasItems]
    ([contentCanvas_contentCanvasId]);
GO

-- Creating foreign key on [TopicContentContentCanvas_ContentCanvas_topicContentId] in table 'ContentCanvas'
ALTER TABLE [dbo].[ContentCanvas]
ADD CONSTRAINT [FK_TopicContentContentCanvas]
    FOREIGN KEY ([TopicContentContentCanvas_ContentCanvas_topicContentId])
    REFERENCES [dbo].[TopicContents]
        ([topicContentId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TopicContentContentCanvas'
CREATE INDEX [IX_FK_TopicContentContentCanvas]
ON [dbo].[ContentCanvas]
    ([TopicContentContentCanvas_ContentCanvas_topicContentId]);
GO

-- Creating foreign key on [learningTrail_learningTrailId] in table 'TrailItems'
ALTER TABLE [dbo].[TrailItems]
ADD CONSTRAINT [FK_LearningTrailTrailItem]
    FOREIGN KEY ([learningTrail_learningTrailId])
    REFERENCES [dbo].[LearningTrails]
        ([learningTrailId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_LearningTrailTrailItem'
CREATE INDEX [IX_FK_LearningTrailTrailItem]
ON [dbo].[TrailItems]
    ([learningTrail_learningTrailId]);
GO

-- Creating foreign key on [courseTopic_courseTopicId] in table 'TrailItems'
ALTER TABLE [dbo].[TrailItems]
ADD CONSTRAINT [FK_CourseTopicTrailItem]
    FOREIGN KEY ([courseTopic_courseTopicId])
    REFERENCES [dbo].[CourseTopics]
        ([courseTopicId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CourseTopicTrailItem'
CREATE INDEX [IX_FK_CourseTopicTrailItem]
ON [dbo].[TrailItems]
    ([courseTopic_courseTopicId]);
GO

-- Creating foreign key on [course_courseId] in table 'LearningTrails'
ALTER TABLE [dbo].[LearningTrails]
ADD CONSTRAINT [FK_CourseLearningTrail]
    FOREIGN KEY ([course_courseId])
    REFERENCES [dbo].[Courses]
        ([courseId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CourseLearningTrail'
CREATE INDEX [IX_FK_CourseLearningTrail]
ON [dbo].[LearningTrails]
    ([course_courseId]);
GO

-- Creating foreign key on [topicContent_topicContentId] in table 'LearningSessions'
ALTER TABLE [dbo].[LearningSessions]
ADD CONSTRAINT [FK_TopicContentLearningSession]
    FOREIGN KEY ([topicContent_topicContentId])
    REFERENCES [dbo].[TopicContents]
        ([topicContentId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TopicContentLearningSession'
CREATE INDEX [IX_FK_TopicContentLearningSession]
ON [dbo].[LearningSessions]
    ([topicContent_topicContentId]);
GO

-- Creating foreign key on [contentCanvas_contentCanvasId] in table 'LearningSessions'
ALTER TABLE [dbo].[LearningSessions]
ADD CONSTRAINT [FK_ContentCanvasLearningSession]
    FOREIGN KEY ([contentCanvas_contentCanvasId])
    REFERENCES [dbo].[ContentCanvas]
        ([contentCanvasId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ContentCanvasLearningSession'
CREATE INDEX [IX_FK_ContentCanvasLearningSession]
ON [dbo].[LearningSessions]
    ([contentCanvas_contentCanvasId]);
GO

-- Creating foreign key on [learningTrail_learningTrailId] in table 'LearningSessions'
ALTER TABLE [dbo].[LearningSessions]
ADD CONSTRAINT [FK_LearningTrailLearningSession]
    FOREIGN KEY ([learningTrail_learningTrailId])
    REFERENCES [dbo].[LearningTrails]
        ([learningTrailId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_LearningTrailLearningSession'
CREATE INDEX [IX_FK_LearningTrailLearningSession]
ON [dbo].[LearningSessions]
    ([learningTrail_learningTrailId]);
GO

-- Creating foreign key on [student_userId] in table 'LearningSessions'
ALTER TABLE [dbo].[LearningSessions]
ADD CONSTRAINT [FK_LearningSessionStudent]
    FOREIGN KEY ([student_userId])
    REFERENCES [dbo].[Users_Student]
        ([userId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_LearningSessionStudent'
CREATE INDEX [IX_FK_LearningSessionStudent]
ON [dbo].[LearningSessions]
    ([student_userId]);
GO

-- Creating foreign key on [learningSession_learningSessionId] in table 'StudentAssesments'
ALTER TABLE [dbo].[StudentAssesments]
ADD CONSTRAINT [FK_StudentAssesmentLearningSession]
    FOREIGN KEY ([learningSession_learningSessionId])
    REFERENCES [dbo].[LearningSessions]
        ([learningSessionId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_StudentAssesmentLearningSession'
CREATE INDEX [IX_FK_StudentAssesmentLearningSession]
ON [dbo].[StudentAssesments]
    ([learningSession_learningSessionId]);
GO

-- Creating foreign key on [studentAssesment_studentAssesmentId] in table 'AssesmentItems'
ALTER TABLE [dbo].[AssesmentItems]
ADD CONSTRAINT [FK_StudentAssesmentAssesmentItem]
    FOREIGN KEY ([studentAssesment_studentAssesmentId])
    REFERENCES [dbo].[StudentAssesments]
        ([studentAssesmentId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_StudentAssesmentAssesmentItem'
CREATE INDEX [IX_FK_StudentAssesmentAssesmentItem]
ON [dbo].[AssesmentItems]
    ([studentAssesment_studentAssesmentId]);
GO

-- Creating foreign key on [topicQuestion_topicQuestionId] in table 'AssesmentItems'
ALTER TABLE [dbo].[AssesmentItems]
ADD CONSTRAINT [FK_TopicQuestionAssesmentItem]
    FOREIGN KEY ([topicQuestion_topicQuestionId])
    REFERENCES [dbo].[TopicQuestions]
        ([topicQuestionId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TopicQuestionAssesmentItem'
CREATE INDEX [IX_FK_TopicQuestionAssesmentItem]
ON [dbo].[AssesmentItems]
    ([topicQuestion_topicQuestionId]);
GO

-- Creating foreign key on [student_userId] in table 'StudentAssesments'
ALTER TABLE [dbo].[StudentAssesments]
ADD CONSTRAINT [FK_StudentAssesmentStudent]
    FOREIGN KEY ([student_userId])
    REFERENCES [dbo].[Users_Student]
        ([userId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_StudentAssesmentStudent'
CREATE INDEX [IX_FK_StudentAssesmentStudent]
ON [dbo].[StudentAssesments]
    ([student_userId]);
GO

-- Creating foreign key on [student_userId] in table 'Subscriptions'
ALTER TABLE [dbo].[Subscriptions]
ADD CONSTRAINT [FK_SubscriptionStudent]
    FOREIGN KEY ([student_userId])
    REFERENCES [dbo].[Users_Student]
        ([userId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SubscriptionStudent'
CREATE INDEX [IX_FK_SubscriptionStudent]
ON [dbo].[Subscriptions]
    ([student_userId]);
GO

-- Creating foreign key on [publishingCompany_publishingCompanyId] in table 'Users_Publisher'
ALTER TABLE [dbo].[Users_Publisher]
ADD CONSTRAINT [FK_PublishingCompanyPublisher]
    FOREIGN KEY ([publishingCompany_publishingCompanyId])
    REFERENCES [dbo].[PublishingCompanies]
        ([publishingCompanyId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PublishingCompanyPublisher'
CREATE INDEX [IX_FK_PublishingCompanyPublisher]
ON [dbo].[Users_Publisher]
    ([publishingCompany_publishingCompanyId]);
GO

-- Creating foreign key on [publisher_userId] in table 'Courses'
ALTER TABLE [dbo].[Courses]
ADD CONSTRAINT [FK_PublisherCourse]
    FOREIGN KEY ([publisher_userId])
    REFERENCES [dbo].[Users_Publisher]
        ([userId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PublisherCourse'
CREATE INDEX [IX_FK_PublisherCourse]
ON [dbo].[Courses]
    ([publisher_userId]);
GO

-- Creating foreign key on [contentCanvas_contentCanvasId] in table 'EncouragementMessages'
ALTER TABLE [dbo].[EncouragementMessages]
ADD CONSTRAINT [FK_ContentCanvasNotificationMessage]
    FOREIGN KEY ([contentCanvas_contentCanvasId])
    REFERENCES [dbo].[ContentCanvas]
        ([contentCanvasId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ContentCanvasNotificationMessage'
CREATE INDEX [IX_FK_ContentCanvasNotificationMessage]
ON [dbo].[EncouragementMessages]
    ([contentCanvas_contentCanvasId]);
GO

-- Creating foreign key on [notificationMessage_encouragementMessageId] in table 'StudentAssesments'
ALTER TABLE [dbo].[StudentAssesments]
ADD CONSTRAINT [FK_NotificationMessageStudentAssesment]
    FOREIGN KEY ([notificationMessage_encouragementMessageId])
    REFERENCES [dbo].[EncouragementMessages]
        ([encouragementMessageId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_NotificationMessageStudentAssesment'
CREATE INDEX [IX_FK_NotificationMessageStudentAssesment]
ON [dbo].[StudentAssesments]
    ([notificationMessage_encouragementMessageId]);
GO

-- Creating foreign key on [TopicQuestionContentCanvas_ContentCanvas_topicQuestionId] in table 'ContentCanvas'
ALTER TABLE [dbo].[ContentCanvas]
ADD CONSTRAINT [FK_TopicQuestionContentCanvas]
    FOREIGN KEY ([TopicQuestionContentCanvas_ContentCanvas_topicQuestionId])
    REFERENCES [dbo].[TopicQuestions]
        ([topicQuestionId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TopicQuestionContentCanvas'
CREATE INDEX [IX_FK_TopicQuestionContentCanvas]
ON [dbo].[ContentCanvas]
    ([TopicQuestionContentCanvas_ContentCanvas_topicQuestionId]);
GO

-- Creating foreign key on [parent_userId] in table 'Users_Student'
ALTER TABLE [dbo].[Users_Student]
ADD CONSTRAINT [FK_ParentStudent]
    FOREIGN KEY ([parent_userId])
    REFERENCES [dbo].[Users_Parent]
        ([userId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ParentStudent'
CREATE INDEX [IX_FK_ParentStudent]
ON [dbo].[Users_Student]
    ([parent_userId]);
GO

-- Creating foreign key on [TopicQuestionAnswer_Answer_topicQuestionId] in table 'AnswerChoices'
ALTER TABLE [dbo].[AnswerChoices]
ADD CONSTRAINT [FK_TopicQuestionAnswer]
    FOREIGN KEY ([TopicQuestionAnswer_Answer_topicQuestionId])
    REFERENCES [dbo].[TopicQuestions]
        ([topicQuestionId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TopicQuestionAnswer'
CREATE INDEX [IX_FK_TopicQuestionAnswer]
ON [dbo].[AnswerChoices]
    ([TopicQuestionAnswer_Answer_topicQuestionId]);
GO

-- Creating foreign key on [course_courseId] in table 'Tags'
ALTER TABLE [dbo].[Tags]
ADD CONSTRAINT [FK_CourseTag]
    FOREIGN KEY ([course_courseId])
    REFERENCES [dbo].[Courses]
        ([courseId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CourseTag'
CREATE INDEX [IX_FK_CourseTag]
ON [dbo].[Tags]
    ([course_courseId]);
GO

-- Creating foreign key on [courseTopic_courseTopicId] in table 'Tags'
ALTER TABLE [dbo].[Tags]
ADD CONSTRAINT [FK_CourseTopicTag]
    FOREIGN KEY ([courseTopic_courseTopicId])
    REFERENCES [dbo].[CourseTopics]
        ([courseTopicId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CourseTopicTag'
CREATE INDEX [IX_FK_CourseTopicTag]
ON [dbo].[Tags]
    ([courseTopic_courseTopicId]);
GO

-- Creating foreign key on [userId] in table 'Users_Student'
ALTER TABLE [dbo].[Users_Student]
ADD CONSTRAINT [FK_Student_inherits_User]
    FOREIGN KEY ([userId])
    REFERENCES [dbo].[Users]
        ([userId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [userId] in table 'Users_Publisher'
ALTER TABLE [dbo].[Users_Publisher]
ADD CONSTRAINT [FK_Publisher_inherits_User]
    FOREIGN KEY ([userId])
    REFERENCES [dbo].[Users]
        ([userId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [userId] in table 'Users_Parent'
ALTER TABLE [dbo].[Users_Parent]
ADD CONSTRAINT [FK_Parent_inherits_User]
    FOREIGN KEY ([userId])
    REFERENCES [dbo].[Users]
        ([userId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [answerId] in table 'AnswerChoices_SingleChoiceAnswer'
ALTER TABLE [dbo].[AnswerChoices_SingleChoiceAnswer]
ADD CONSTRAINT [FK_SingleChoiceAnswer_inherits_AnswerChoice]
    FOREIGN KEY ([answerId])
    REFERENCES [dbo].[AnswerChoices]
        ([answerId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [userId] in table 'Users_Admin'
ALTER TABLE [dbo].[Users_Admin]
ADD CONSTRAINT [FK_Admin_inherits_User]
    FOREIGN KEY ([userId])
    REFERENCES [dbo].[Users]
        ([userId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------